local zhitong = fk.CreateSkill {
  name = "lvshi__zhitong",
  tags = {"Phase"}
}

Fk:loadTranslationTable{
  ["lvshi__zhitong"] = "志通",
  [":lvshi__zhitong"] = "阶段技，你可令两名其他角色同时交给你一至X张手牌，然后你交给这些角色各至多X张手牌，若这些角色的手牌数相同，你回复1点体力。（X为你发动此技能次数+1）",
  ["#zhitong-active"] = "你可令两名其他角色同时交给你1至%arg张手牌",
  ["#lvshi__zhitong"] = "志通：请选择交给%src的手牌",
  ["#lvshi__zhitong-give"] = "志通：请选择分配的牌和角色，或取消继续分配",

  ["$lvshi__zhitong1"] = "合左抑右，定两家之盟。",
  ["$lvshi__zhitong2"] = "求同存异，邀英雄问鼎。",
}

zhitong:addEffect("active", {
  anim_type = "offensive",
  prompt = function(self, player)
    local n = player:usedSkillTimes(zhitong.name, Player.HistoryGame) + 2
    return "#zhitong-active:::"..n
  end,
  max_phase_use_time = 1,
  card_num = 0,
  target_num = 2,
  target_filter = function(self, player, to_select, selected)
    return not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local n = player:usedSkillTimes(self.name, Player.HistoryGame) + 1
    local params = {
      players = effect.tos,
      min_num = 1,
      max_num = n,
      include_equip = false,
      cancelable = false,
      skill_name = zhitong.name,
      prompt = "#lvshi__zhitong:"..player.id
    }
    local result = room:askToJointCards(player, params)
    local cards = result[effect.tos[1]]
    table.insertTableIfNeed(cards, result[effect.tos[2]])
    room:obtainCard(player, cards, true, fk.ReasonGive, player.id, self.name)
    local targets = table.filter(effect.tos, function (p) return p:isAlive() end)
    room:askToYiji(player, {
      cards = player:getCardIds("h"),
      min_num = #targets,
      max_num = n * #targets,
      single_max = n,
      targets = targets,
      skill_name = zhitong.name,
      prompt = "#lvshi__zhitong-give",
      cancelable = false,
    })
    if targets[1]:getHandcardNum() == targets[2]:getHandcardNum() then
      room:recover{who = player, num = 1, recoverBy = player, skillName = self.name}
    end
  end,
})

return zhitong
